package com.dream.testtubebaby_doctor.adapter;

import android.content.Context;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.dream.testtubebaby_doctor.utils.FaceTool;

public class FaceAdapter extends BaseAdapter {

	private Context mContext;

	public FaceAdapter(Context context) {
		mContext = context;
	}

	public int getCount() {
		return FaceTool.getInstance().mFaces.length;
	}

	public Object getItem(int position) {
		return FaceTool.getInstance().getFaceBitmap(position, mContext);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView face = null;
		if (convertView == null) {
			face = new ImageView(mContext);
			LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
					LayoutParams.WRAP_CONTENT);
			int widthAndHeight = (int) TypedValue.applyDimension(
					TypedValue.COMPLEX_UNIT_DIP, 30, mContext.getResources()
							.getDisplayMetrics());
			params.width = widthAndHeight;
			params.height = widthAndHeight;
			face.setLayoutParams(params);
			face.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
		} else {
			face = (ImageView) convertView;
		}
		face.setImageBitmap(FaceTool.getInstance().getFaceBitmap(position,
				mContext));
		return face;
	}

}
